package com.southwind.springboottest.studykotlin.s2;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @description：TODO
 * @author： HXG
 * @create： 2024/4/19 10:07
 */
public class KtBase45 {
    public static void main(String[] args) {
        String sourcePwd = "ABCDEFGHIIKLMNOPQRSTUVWXYZ";
        System.out.println("原始密码是：" + sourcePwd);

        // 使用数字替换字符实现加密
        Pattern pattern = Pattern.compile("[AKMNO]");
        Matcher matcher = pattern.matcher(sourcePwd);
        StringBuffer newPwdBuffer = new StringBuffer();
        while (matcher.find()) {
            String replacement = "";
            switch (matcher.group()) {
                case "A":
                    replacement = "9";
                    break;
                case "K":
                    replacement = "3";
                    break;
                case "M":
                    replacement = "5";
                    break;
                case "N":
                    replacement = "1";
                    break;
                case "O":
                    replacement = "4";
                    break;
                default:
                    replacement = matcher.group();
            }
            matcher.appendReplacement(newPwdBuffer, replacement);
        }
        matcher.appendTail(newPwdBuffer);
        String newPwd = newPwdBuffer.toString();

        System.out.println("加密后的密码是：" + newPwd);
    }
}
